#include "rationalcurveitem.h"
#include "curvescene.h"
#include "curvelib/irational.h"

RationalCurveItem::RationalCurveItem(IRatioF *numCurve, CurveScene *scene) :
    CurveItem(numCurve, scene)
{
    m_numCurve = numCurve;
}

void RationalCurveItem::AddPoint(const QPointF &pos, double weight)
{
    m_numCurve->AddPoint(pos, weight);

    SetupControlHandles();
    Update();
}

void RationalCurveItem::AddPoint(const QPointF &pos)
{
    AddPoint(pos, 1.0);

    SetupControlHandles();
    Update();
}

std::vector<double> * RationalCurveItem::GetWeightsPtr()
{
    return m_numCurve->GetWeightsPtr();
}

void RationalCurveItem::SetControlPoint(int i, const QPointF &pos, double weight)
{
    m_numCurve->SetPoint(i, pos, weight);
}

void RationalCurveItem::SetWeight(int i, double weight)
{
    m_numCurve->SetWeight(i, weight);
}

double RationalCurveItem::GetWeight(int i)
{
    return m_numCurve->GetWeight(i);
}

IRatioF * RationalCurveItem::GetNumCurve()
{
    return m_numCurve;
}

QPainterPath RationalCurveItem::shape() const
{
    QPainterPath path;
    QPolygonF polygon;

    QVector<QPointF> points = m_numCurve->GetCurvePoints();
    polygon << points;

    std::reverse(points.begin(), points.end());
    polygon << points;

    path.addPolygon(polygon);
    return path;
}


